home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / drivewlk.cls < prev    next >
Text File  |  1997-06-14  |  2KB  |  94 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CDriveWalker"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. ' Implement Basic-friendly version of IEnumVARIANT
  13. Implements IVariantWalker
  14. ' Delegate to class that implements real IEnumVARIANT
  15. Private vars As CEnumVariant
  16. ' Connect back to parent collection
  17. Private connect As CDrives
  18.  
  19. Public Enum EErrorDriveWalker
  20.     eeBaseDriveWalker = 13040   ' CDriveWalker
  21. End Enum
  22.  
  23. ' Private state data
  24. Private i As Long
  25.  
  26. Private Sub Class_Initialize()
  27.     ' Initialize position in collection
  28.     i = 1
  29.     ' Connect walker to CEnumVariant so it can call methods
  30.     Set vars = New CEnumVariant
  31.     vars.Attach Me
  32. End Sub
  33.  
  34. ' Receive connection from CDrives
  35. Sub Attach(connectA As CDrives)
  36.     Set connect = connectA
  37. End Sub
  38.  
  39. ' Return IEnumVARIANT (indirectly) to client collection
  40. Friend Property Get NewEnum() As IEnumVARIANT
  41.     Set NewEnum = vars
  42. End Property
  43.  
  44. ' Implement IVariantWalker methods
  45. Private Function IVariantWalker_More(v As Variant) As Boolean
  46.     ' Find the next drive and return it through reference
  47.     Do While i <= 26
  48.         ' Check flags to see if next drive exists
  49.         If MBytes.RShiftDWord(connect.DriveFlags, i - 1) And 1 Then
  50.             Dim drive As CDrive
  51.             Set drive = New CDrive
  52.             drive.Root = i
  53.             Set v = drive
  54.             IVariantWalker_More = True
  55.             i = i + 1
  56.             Exit Function
  57.         End If
  58.         i = i + 1
  59.     Loop
  60. End Function
  61.  
  62. Private Sub IVariantWalker_Skip(c As Long)
  63.     ' Skip ahead in the iteration
  64.     i = i + c
  65. End Sub
  66.  
  67. Private Sub IVariantWalker_Reset()
  68.     ' Reset the iteration
  69.     i = 1
  70. End Sub
  71. '
  72.  
  73. #If fComponent = 0 Then
  74. Private Sub ErrRaise(e As Long)
  75.     Dim sText As String, sSource As String
  76.     If e > 1000 Then
  77.         sSource = App.ExeName & ".DriveWalker"
  78.         Select Case e
  79.         Case eeBaseDriveWalker
  80.             BugAssert True
  81.        ' Case ee...
  82.        '     Add additional errors
  83.         End Select
  84.         Err.Raise COMError(e), sSource, sText
  85.     Else
  86.         ' Raise standard Visual Basic error
  87.         sSource = App.ExeName & ".VBError"
  88.         Err.Raise e, sSource
  89.     End If
  90. End Sub
  91. #End If
  92.  
  93.  
  94.